package com.ys.web.user.risk;

import com.ys.utils.base.j2se.StringHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Component
public class RiskManager{
    @Autowired
    private RiskService riskService;

    private static Set<Long> riskList = new HashSet<>();

    @PostConstruct
    void init() {
        load();
    }

    private void load(){
        Risk risk = new Risk();
        risk.setStatus(1);
        List<Risk> risks = riskService.getRiskList(risk);
        if(StringHandler.isNotEmpty(risks)){
            riskList = risks.stream().map(Risk::getUserId).collect(Collectors.toSet());
        }
    }

    public static void addRisk(long sysId){
        riskList.add(sysId);
    }

    public static boolean contains(long sysId){
        return riskList.contains(sysId);
    }

    public static void delRisk(long sysId){
        riskList.remove(sysId);
    }
}
